package com.face.server.service.impl;

import com.face.RespMsg;
import com.face.server.vo.DataClass;
import com.face.server.dao.IndexDAO;
import com.face.server.vo.IndexInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class IndexService {

    @Autowired
    IndexDAO indexDAO;

    public RespMsg build(int buildSkip, int buildLimit) {
        List<DataClass> register = indexDAO.count(buildSkip, buildLimit, true);
        List<DataClass> notRegister = indexDAO.count(buildSkip, buildLimit, false);
        int studentNum = 0;
        int studentWithFace = 0;
        int visitorNum = 0;
        int visitorWithFace = 0;
        for (DataClass dataClass :
                register) {
            if (dataClass.getType() == 1) {
                // 代表访问者
                visitorNum += dataClass.getCount();
                visitorWithFace += dataClass.getCount();
            } else {
                studentNum += dataClass.getCount();
                studentWithFace += dataClass.getCount();
            }
        }

        for (DataClass dataClass : notRegister) {
            if (dataClass.getType() == 1) {
                visitorNum += dataClass.getCount();
            } else {
                studentNum += dataClass.getCount();
            }
        }
        return RespMsg.build(new IndexInfo(studentNum, studentWithFace, visitorNum, visitorWithFace));
    }
}
